import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';

class DioInterceptors extends Interceptor {
  // 请求拦截
  @override
  void onRequest(
    RequestOptions options,
    RequestInterceptorHandler handler,
  ) {
    // print("发送请求");
    // print(options);
    // print(handler);

    // 继续发送请求
    handler.next(options);
  }

  // 响应拦截
  @override
  void onResponse(
    Response response,
    ResponseInterceptorHandler handler,
  ) {
    // print("收到响应");
    // print(response);
    // print(handler);
    // 继续响应
    handler.next(response);
  }

  @override
  void onError(
    DioException err,
    ErrorInterceptorHandler handler,
  ) {
    // print("收到错误");
    // print(err);
    // print(handler);
    if (err.message != null) {
      BotToast.showText(text: err.message!, align: Alignment.center);
    }
    handler.next(err);
  }
}
